package cn.jeefast.modules.platform.controller;


import cn.jeefast.common.entity.MbCommissioner;
import cn.jeefast.common.utils.R;
import cn.jeefast.modules.platform.service.MbCommissioner1Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.jeefast.common.base.BaseController;

import java.util.List;

/**
 * <p>
 * 医学专员表
 前端控制器
 * </p>
 *
 * @author theodo
 * @since 2020-01-06
 */
@RestController
@RequestMapping("/mbCommissioner")
@CrossOrigin
public class MbCommissionerController extends BaseController {

    @Autowired
    private MbCommissioner1Service commissioner1Service;

    /**
     * 添加或修改专员
     * @param commissioner
     * @return
     */
    @RequestMapping("/addOrSave")
	public R addOrSave(MbCommissioner commissioner){
        return commissioner1Service.addOrSave(commissioner);
    }

    /**
     * 获取项目关联的专员
     * @param projId
     * @return
     */
    @RequestMapping("/list")
    public R list(Long projId, Integer page, Integer limit){
        page = (page-1)*limit;
        List<MbCommissioner> mbCommissioners = commissioner1Service.listByProj(projId, page, limit);
        for (MbCommissioner mbc:mbCommissioners) {
            mbc.setCommPassword(null);
        }
        EntityWrapper ew = new EntityWrapper();
        ew.eq("proj_id",projId);
        List list = commissioner1Service.selectList(ew);
        return R.ok().put("data",mbCommissioners).put("count",list.size());
    }

    /**
     * 删除专员
     * @param commId
     * @return
     */
    @RequestMapping("/delete")
    public R delete(Long commId){
        commissioner1Service.deleteById(commId);
        return R.ok();
    }
}
